<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="{...theConfig,...$attrs}">
			<template v-slot:importDialog="{ row, show }">
				<ImportForm @refresh="handleRefresh" :api="baseConfig.api" :key="show" :nowRowData="row"></ImportForm>
			</template>
			<template v-slot:addDialog="{ row, show }">
				<TabForm @refresh="handleRefresh" :api="baseConfig.api" :key="show" :nowRowData="row"></TabForm>
			</template>
			<template v-slot:ArchivesDialog="{ row, show }">
				<Archives
					@refresh="handleRefresh"
					@refreshPage="handleRefreshPage"
					@rechange="handleOperate"
					:api="baseConfig.api"
					:key="show"
					:nowRowData="row"
				></Archives>
			</template>
			<template v-slot:RechangeDialog="{ row, show }">
				<Rechange @refresh="handleRefresh" :api="baseConfig.api" :key="show" :nowRowData="row"></Rechange>
			</template>
			<template v-slot:AssociateDialog="{ row, show }">
				<Associate @refresh="handleRefresh" :api="baseConfig.api" :key="show" :nowRowData="row"></Associate>
			</template>
		</aplid-base-crud>
	</BaseContainer>
</template>

<script lang="ts" setup>
import { baseConfig } from './config'
import ImportForm from './ImportForm/index.vue'
import TabForm from './TabForm/index.vue'
import Rechange from './Rechange/index.vue'
import Archives from './Archives/index.vue'
import Associate from './Associate/index.vue'
import { editConfig } from '@/views/datacenter/comprehensiveQueries/utils/index'
import { cloneDeep } from 'lodash-es'

type Props = {
  isComprehensiveQueries?:boolean
}
let props = withDefaults(defineProps<Props>(),{
  isComprehensiveQueries:false
})
let theConfig:any = ref({})
if(baseConfig){
  let defaultConfig = cloneDeep(baseConfig)
  if(props.isComprehensiveQueries){
    theConfig.value = editConfig(defaultConfig)
  }else{
    theConfig.value = baseConfig
  }
}

const crud = ref(null)

const handleRefresh = (query?) => {
	nextTick(() => {
		crud.value.refreshChange(query)
	})
}
const handleRefreshPage = () => {
	nextTick(() => {
		crud.value.refreshChange({}, true)
	})
}
const handleOperate = (type, row, title) => {
	nextTick(() => {
		crud.value.handleOperate(type, row, title)
	})
}
defineExpose({
	handleRefresh
})
</script>

<style lang="scss" scoped></style>
